package com.lzq.his.service;

import com.lzq.his.domain.DeptMajor;
import com.lzq.his.mapper.DeptMajorMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;

@Service
public class DeptMajorService {

    @Autowired
    private DeptMajorMapper deptMajorMapper;

    public List<DeptMajor> selectAll() {
        return deptMajorMapper.selectByExample(null);
    }


    public void deleteById(String id) {
        deptMajorMapper.deleteByPrimaryKey(Integer.parseInt(id));
    }

    public void save(DeptMajor deptMajor) {
        if (deptMajor.getId() == null) {
            Random random = new Random();
            deptMajor.setId(random.nextInt());
            deptMajorMapper.insert(deptMajor);
        } else {
            deptMajorMapper.updateByPrimaryKeySelective(deptMajor);
        }
    }
}
